package com.unittec.drainage.gateway.config;

/*
 * 
 * import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
 * import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import
 * org.springframework.web.socket.config.annotation.StompEndpointRegistry; import
 * org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import
 * org.springframework.web.socket.server.standard.ServerEndpointExporter;
 * 
 */
/**
 * @author wuxinwei
 *         <p>
 *         注入ServerEndpointExporter， 这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    /**
     * 注入ServerEndpointExporter， 这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // 开启/bullet端点
        registry.addEndpoint("/websocket")
            // 允许跨域访问
            //.setAllowedOrigins("*")
            // 使用sockJS
            .withSockJS();
    }

}
